home *** CD-ROM | disk | FTP | other *** search
/ Gamers Delight 2 / Gamers Delight 2.iso / Aminet / game / board / Chaos53src.lha / chaos / src / PlayersAmi.c < prev    next >
C/C++ Source or Header  |  1994-11-19  |  26KB  |  770 lines

  1. /*  Chaos:            The Chess HAppening Organisation System    V5.3
  2.     Copyright (C)   1993    Jochen Wiedmann
  3.  
  4.     This program is free software; you can redistribute it and/or modify
  5.     it under the terms of the GNU General Public License as published by
  6.     the Free Software Foundation; either version 2 of the License, or
  7.     (at your option) any later version.
  8.  
  9.     This program is distributed in the hope that it will be useful,
  10.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.     GNU General Public License for more details.
  13.  
  14.     You should have received a copy of the GNU General Public License
  15.     along with this program; if not, write to the Free Software
  16.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17.  
  18.  
  19.     $RCSfile: PlayersAmi.c,v $
  20.     $Revision: 3.2 $
  21.     $Date: 1994/11/19 19:32:01 $
  22.  
  23.     This file contains the system dependent functions for the Players menu.
  24.  
  25.     Computer:    Amiga 1200            Compiler:    Dice 2.07.54 (3.0)
  26.  
  27.     Author:    Jochen Wiedmann
  28.         Am Eisteich 9
  29.       72555 Metzingen
  30.         Tel. 07123 / 14881
  31.         Internet: wiedmann@mailserv.zdv.uni-tuebingen.de
  32. */
  33.  
  34.  
  35. #ifndef CHAOS_H
  36. #include "chaos.h"
  37. #endif
  38.  
  39.  
  40.  
  41.  
  42. /*
  43.     AskExtContinue() brings up a requester asking a question and lets the
  44.     user select between different possibilities.
  45.  
  46.     Inputs: str     a printf()-like format string
  47.         buttons a string containing the different choices, separated by
  48.             a '|', for example "Yes|No|Cancel"
  49.         Other arguments may follow. These are used in the format string.
  50.  
  51.     Results: 0 for the rightmost choice and 1, 2, 3, ... for the other
  52.          choices. (In the "Yes|No|Cancel" example this would be 1 for
  53.          "Yes", 2 for "No" and 0 for "Cancel".
  54. */
  55. int AskExtContinue(char *str, char *buttons, ...)
  56.  
  57. #ifdef AMIGA
  58. { return(MUI_RequestA(App, MainWnd, 0, (char *) GetChaosString(MSG_ATTENTION),
  59.               buttons, str, (APTR) ((&buttons)+1)));
  60. }
  61. #endif
  62.  
  63.  
  64.  
  65.  
  66. /*
  67.     The AskContinue() function brings up a requester asking a Yes/No
  68.     question like "Do you really want to delete player p?"
  69.  
  70.     Inputs: a printf()-like format string, possibly followed by
  71.         the corresponding arguments.
  72.  
  73.     Results: TRUE, if the user selected Ok, FALSE otherwise
  74. */
  75. int AskContinue(char *str, ...)
  76.  
  77. #ifdef AMIGA
  78. { return(MUI_RequestA(App, MainWnd, 0,
  79.               (char *) GetChaosString(MSG_ATTENTION),
  80.               (char *) GetChaosString(MSG_YES_NO),
  81.               str, (APTR) ((&str)+1)));
  82. }
  83. #endif    /*  AMIGA   */
  84.  
  85.  
  86.  
  87.  
  88. /*
  89.     The TerminatePlrWnd() function deletes the window that allows to edit
  90.     players.
  91. */
  92. #ifdef AMIGA
  93. static APTR PlrWnd = NULL;  /*    Player window                */
  94. static APTR PlrOkGad;        /*    Ok gadget (player window)           */
  95. static APTR PlrCancelGad;   /*    Cancel gadget (player window)       */
  96. static APTR NameGad;        /*    Name gadget                */
  97. static APTR StreetGad;        /*    Street gadget                */
  98. static APTR VillageGad;     /*    Village gadget                */
  99. static APTR ChessClubGad;   /*    Chess club gadget            */
  100. static APTR PhoneGad;        /*    Phone gadget                */
  101. static APTR BirthdayGad;    /*    Birthday gadget             */
  102. static APTR DWZGad;        /*    DWZ gadget                */
  103. static APTR ELOGad;        /*    ELO gadget                */
  104. static APTR SeniorGad;        /*    Senior gadget                */
  105. static APTR JuniorGad;        /*    Junior gadget                */
  106. static APTR WomanGad;        /*    Woman gadget                */
  107. static APTR JuniorAGad;     /*    Junior (A) gadget                   */
  108. static APTR JuniorBGad;     /*    Junior (B) gadget                   */
  109. static APTR JuniorCGad;     /*    Junior (C) gadget                   */
  110. static APTR JuniorDGad;     /*    Junior (D) gadget                   */
  111. static APTR JuniorEGad;     /*    Junior (E) gadget                   */
  112. void TerminatePlrWnd(void)
  113.  
  114. { if (PlrWnd != NULL)
  115.   { set(PlrWnd, MUIA_Window_Open, FALSE);
  116.     DoMethod(App, OM_REMMEMBER, PlrWnd);
  117.     MUI_DisposeObject(PlrWnd);
  118.     PlrWnd = NULL;
  119.   }
  120. }
  121. #endif    /*  AMIGA   */
  122.  
  123.  
  124.  
  125.  
  126. /*
  127.     The InitPlrWnd() function creates the window that allows to edit
  128.     a player.
  129.  
  130.     Inputs:    title    the windows title
  131.  
  132.     Results:    TRUE, if successful, FALSE otherwise
  133. */
  134. #define ID_PlrWnd_Cancel    303
  135. #define ID_PlrWnd_Ok        304
  136. int InitPlrWnd(char *title)
  137.  
  138. #ifdef AMIGA
  139. { int Ok_SC = *GetChaosString(MSG_OK_SC);
  140.   int Cancel_SC = *GetChaosString(MSG_CANCEL_SC);
  141.  
  142.   PlrWnd = WindowObject,
  143.         MUIA_Window_ID, MAKE_ID('P','L','R','I'),
  144.         MUIA_Window_Width, MUIV_Window_Width_MinMax(50),
  145.         MUIA_Window_Title, title,
  146.         WindowContents, VGroup,
  147.         Child, HGroup,
  148.             Child, VGroup,
  149.             MUIA_Weight, 300,
  150.             Child, ColGroup(2),
  151.                 Child, Label2(GetChaosString(MSG_NAME_INPUT)),
  152.                 Child, NameGad = StringObject,
  153.                 StringFrame,
  154.                 MUIA_String_MaxLen, NAMELEN+1,
  155.                 End,
  156.                 Child, Label2(GetChaosString(MSG_STREET_INPUT)),
  157.                 Child, StreetGad = StringObject,
  158.                 StringFrame,
  159.                 MUIA_String_MaxLen, NAMELEN+1,
  160.                 End,
  161.                 Child, Label2(GetChaosString(MSG_VILLAGE_INPUT)),
  162.                 Child, VillageGad = StringObject,
  163.                 StringFrame,
  164.                 MUIA_String_MaxLen, NAMELEN+1,
  165.                 End,
  166.                 Child, Label2(GetChaosString(MSG_CHESS_CLUB_INPUT)),
  167.                 Child, ChessClubGad = StringObject,
  168.                 StringFrame,
  169.                 MUIA_String_MaxLen, NAMELEN+1,
  170.                 End,
  171.                 Child, Label2(GetChaosString(MSG_PHONE_INPUT)),
  172.                 Child, PhoneGad = StringObject,
  173.                 StringFrame,
  174.                 MUIA_String_MaxLen, PHONENRLEN+1,
  175.                 End,
  176.                 Child, Label2(GetChaosString(MSG_BIRTHDAY_INPUT)),
  177.                 Child, BirthdayGad = StringObject,
  178.                 StringFrame,
  179.                 MUIA_String_MaxLen, BIRTHDAYLEN+1,
  180.                 End,
  181.             End,
  182.             Child, HGroup,
  183.                 Child, Label2(GetChaosString(MSG_DWZ_INPUT)),
  184.                 Child, DWZGad = StringObject, StringFrame,
  185.                 MUIA_String_MaxLen, DWZLEN+1,
  186.                 MUIA_String_Accept, "0123456789-",
  187.                 End,
  188.                 Child, HSpace(0),
  189.                 Child, Label2(GetChaosString(MSG_ELO_INPUT)),
  190.                 Child, ELOGad = StringObject, StringFrame,
  191.                 MUIA_String_MaxLen, DWZLEN+1,
  192.                 MUIA_String_Accept, "0123456789",
  193.                 End,
  194.             End,
  195.             End,
  196.             Child, MUI_NewObject(MUIC_Rectangle,
  197.             MUIA_Weight, 50,
  198.             End,
  199.             Child, ColGroup(2),
  200.             Child, SeniorGad = CheckMark(FALSE),
  201.             Child, Label2(GetChaosString(MSG_SENIORS_INPUT)),
  202.             Child, JuniorGad = CheckMark(FALSE),
  203.             Child, Label2(GetChaosString(MSG_JUNIORS_INPUT)),
  204.             Child, WomanGad = CheckMark(FALSE),
  205.             Child, Label2(GetChaosString(MSG_WOMEN_INPUT)),
  206.             Child, JuniorAGad = CheckMark(FALSE),
  207.             Child, Label2(GetChaosString(MSG_JUNIORSA_INPUT)),
  208.             Child, JuniorBGad = CheckMark(FALSE),
  209.             Child, Label2(GetChaosString(MSG_JUNIORSB_INPUT)),
  210.             Child, JuniorCGad = CheckMark(FALSE),
  211.             Child, Label2(GetChaosString(MSG_JUNIORSC_INPUT)),
  212.             Child, JuniorDGad = CheckMark(FALSE),
  213.             Child, Label2(GetChaosString(MSG_JUNIORSD_INPUT)),
  214.             Child, JuniorEGad = CheckMark(FALSE),
  215.             Child, Label2(GetChaosString(MSG_JUNIORSE_INPUT)),
  216.             End,
  217.         End,
  218.         Child, HGroup,
  219.             MUIA_Group_SameSize, TRUE,
  220.             Child, PlrOkGad = KeyButton(GetChaosString(MSG_OK), Ok_SC),
  221.             Child, HSpace(0),
  222.             Child, HSpace(0),
  223.             Child, PlrCancelGad = KeyButton(GetChaosString(MSG_CANCEL_INPUT), Cancel_SC),
  224.         End,
  225.         End,
  226.     End;
  227.  
  228.   if (!PlrWnd)
  229.   { return(FALSE);
  230.   }
  231.   DoMethod(App, OM_ADDMEMBER, PlrWnd);
  232.  
  233.   /*
  234.       Setting up the notification events for the player input window
  235.   */
  236.   DoMethod(PlrWnd, MUIM_Notify, MUIA_Window_CloseRequest, TRUE, App, 2,
  237.        MUIM_Application_ReturnID, ID_PlrWnd_Cancel);
  238.   DoMethod(PlrWnd, MUIM_Notify, MUIA_Window_InputEvent, "ctrl return",
  239.        App, 2, MUIM_Application_ReturnID, ID_PlrWnd_Ok);
  240.   DoMethod(PlrOkGad, MUIM_Notify, MUIA_Pressed, FALSE, App, 2,
  241.        MUIM_Application_ReturnID, ID_PlrWnd_Ok);
  242.   DoMethod(PlrCancelGad, MUIM_Notify, MUIA_Pressed, FALSE, App, 2,
  243.        MUIM_Application_ReturnID, ID_PlrWnd_Cancel);
  244.  
  245.   /*
  246.       Setting up the cycle chain in the player input window
  247.   */
  248.   DoMethod(PlrWnd, MUIM_Window_SetCycleChain,
  249.        NameGad, StreetGad, VillageGad, ChessClubGad, PhoneGad,
  250.        BirthdayGad, DWZGad, ELOGad, PlrOkGad, PlrCancelGad,
  251.        SeniorGad, JuniorGad, WomanGad, JuniorAGad, JuniorBGad,
  252.        JuniorCGad, JuniorDGad, JuniorEGad, NULL);
  253.   DoMethod(NameGad, MUIM_Notify, MUIA_String_Acknowledge, MUIV_EveryTime,
  254.        PlrWnd, 3, MUIM_Set, MUIA_Window_ActiveObject, StreetGad);
  255.   DoMethod(StreetGad, MUIM_Notify, MUIA_String_Acknowledge, MUIV_EveryTime,
  256.        PlrWnd, 3, MUIM_Set, MUIA_Window_ActiveObject, VillageGad);
  257.   DoMethod(VillageGad, MUIM_Notify, MUIA_String_Acknowledge, MUIV_EveryTime,
  258.        PlrWnd, 3, MUIM_Set, MUIA_Window_ActiveObject, ChessClubGad);
  259.   DoMethod(ChessClubGad, MUIM_Notify, MUIA_String_Acknowledge, MUIV_EveryTime,
  260.        PlrWnd, 3, MUIM_Set, MUIA_Window_ActiveObject, PhoneGad);
  261.   DoMethod(PhoneGad, MUIM_Notify, MUIA_String_Acknowledge, MUIV_EveryTime,
  262.        PlrWnd, 3, MUIM_Set, MUIA_Window_ActiveObject, BirthdayGad);
  263.   DoMethod(BirthdayGad, MUIM_Notify, MUIA_String_Acknowledge, MUIV_EveryTime,
  264.        PlrWnd, 3, MUIM_Set, MUIA_Window_ActiveObject, DWZGad);
  265.   DoMethod(DWZGad, MUIM_Notify, MUIA_String_Acknowledge, MUIV_EveryTime,
  266.        PlrWnd, 3, MUIM_Set, MUIA_Window_ActiveObject, ELOGad);
  267.   DoMethod(ELOGad, MUIM_Notify, MUIA_String_Acknowledge, MUIV_EveryTime,
  268.        PlrWnd, 3, MUIM_Set, MUIA_Window_ActiveObject, NameGad);
  269.  
  270.   /*
  271.       Of course you cannot be both senior and junior. Selecting a junior
  272.       gadget deselects a junior gadget and vice versa. Further you can
  273.       only be one of JuniorA, JuniorB, JuniorC, JuniorD and JuniorE.
  274.  
  275.       On the other hand a JuniorA is a Junior too.
  276.   */
  277.   DoMethod(JuniorAGad, MUIM_Notify, MUIA_Selected, TRUE, JuniorBGad, 4,
  278.        MUIM_Set, MUIA_Selected, FALSE);
  279.   DoMethod(JuniorAGad, MUIM_Notify, MUIA_Selected, TRUE, JuniorCGad, 4,
  280.        MUIM_Set, MUIA_Selected, FALSE);
  281.   DoMethod(JuniorAGad, MUIM_Notify, MUIA_Selected, TRUE, JuniorDGad, 4,
  282.        MUIM_Set, MUIA_Selected, FALSE);
  283.   DoMethod(JuniorAGad, MUIM_Notify, MUIA_Selected, TRUE, JuniorEGad, 4,
  284.        MUIM_Set, MUIA_Selected, FALSE);
  285.   DoMethod(JuniorAGad, MUIM_Notify, MUIA_Selected, TRUE, SeniorGad, 4,
  286.        MUIM_Set, MUIA_Selected, FALSE);
  287.   DoMethod(JuniorAGad, MUIM_Notify, MUIA_Selected, TRUE, JuniorGad, 4,
  288.        MUIM_Set, MUIA_Selected, TRUE);
  289.  
  290.   DoMethod(JuniorBGad, MUIM_Notify, MUIA_Selected, TRUE, JuniorAGad, 4,
  291.        MUIM_Set, MUIA_Selected, FALSE);
  292.   DoMethod(JuniorBGad, MUIM_Notify, MUIA_Selected, TRUE, JuniorCGad, 4,
  293.        MUIM_Set, MUIA_Selected, FALSE);
  294.   DoMethod(JuniorBGad, MUIM_Notify, MUIA_Selected, TRUE, JuniorDGad, 4,
  295.        MUIM_Set, MUIA_Selected, FALSE);
  296.   DoMethod(JuniorBGad, MUIM_Notify, MUIA_Selected, TRUE, JuniorEGad, 4,
  297.        MUIM_Set, MUIA_Selected, FALSE);
  298.   DoMethod(JuniorBGad, MUIM_Notify, MUIA_Selected, TRUE, SeniorGad, 4,
  299.        MUIM_Set, MUIA_Selected, FALSE);
  300.   DoMethod(JuniorBGad, MUIM_Notify, MUIA_Selected, TRUE, JuniorGad, 4,
  301.        MUIM_Set, MUIA_Selected, TRUE);
  302.  
  303.   DoMethod(JuniorCGad, MUIM_Notify, MUIA_Selected, TRUE, JuniorAGad, 4,
  304.        MUIM_Set, MUIA_Selected, FALSE);
  305.   DoMethod(JuniorCGad, MUIM_Notify, MUIA_Selected, TRUE, JuniorBGad, 4,
  306.        MUIM_Set, MUIA_Selected, FALSE);
  307.   DoMethod(JuniorCGad, MUIM_Notify, MUIA_Selected, TRUE, JuniorDGad, 4,
  308.        MUIM_Set, MUIA_Selected, FALSE);
  309.   DoMethod(JuniorCGad, MUIM_Notify, MUIA_Selected, TRUE, JuniorEGad, 4,
  310.        MUIM_Set, MUIA_Selected, FALSE);
  311.   DoMethod(JuniorCGad, MUIM_Notify, MUIA_Selected, TRUE, SeniorGad, 4,
  312.        MUIM_Set, MUIA_Selected, FALSE);
  313.   DoMethod(JuniorCGad, MUIM_Notify, MUIA_Selected, TRUE, JuniorGad, 4,
  314.        MUIM_Set, MUIA_Selected, TRUE);
  315.  
  316.   DoMethod(JuniorDGad, MUIM_Notify, MUIA_Selected, TRUE, JuniorAGad, 4,
  317.        MUIM_Set, MUIA_Selected, FALSE);
  318.   DoMethod(JuniorDGad, MUIM_Notify, MUIA_Selected, TRUE, JuniorBGad, 4,
  319.        MUIM_Set, MUIA_Selected, FALSE);
  320.   DoMethod(JuniorDGad, MUIM_Notify, MUIA_Selected, TRUE, JuniorCGad, 4,
  321.        MUIM_Set, MUIA_Selected, FALSE);
  322.   DoMethod(JuniorDGad, MUIM_Notify, MUIA_Selected, TRUE, JuniorEGad, 4,
  323.        MUIM_Set, MUIA_Selected, FALSE);
  324.   DoMethod(JuniorDGad, MUIM_Notify, MUIA_Selected, TRUE, SeniorGad, 4,
  325.        MUIM_Set, MUIA_Selected, FALSE);
  326.   DoMethod(JuniorDGad, MUIM_Notify, MUIA_Selected, TRUE, JuniorGad, 4,
  327.        MUIM_Set, MUIA_Selected, TRUE);
  328.  
  329.   DoMethod(JuniorEGad, MUIM_Notify, MUIA_Selected, TRUE, JuniorAGad, 4,
  330.        MUIM_Set, MUIA_Selected, FALSE);
  331.   DoMethod(JuniorEGad, MUIM_Notify, MUIA_Selected, TRUE, JuniorBGad, 4,
  332.        MUIM_Set, MUIA_Selected, FALSE);
  333.   DoMethod(JuniorEGad, MUIM_Notify, MUIA_Selected, TRUE, JuniorCGad, 4,
  334.        MUIM_Set, MUIA_Selected, FALSE);
  335.   DoMethod(JuniorEGad, MUIM_Notify, MUIA_Selected, TRUE, JuniorDGad, 4,
  336.        MUIM_Set, MUIA_Selected, FALSE);
  337.   DoMethod(JuniorEGad, MUIM_Notify, MUIA_Selected, TRUE, SeniorGad, 4,
  338.        MUIM_Set, MUIA_Selected, FALSE);
  339.   DoMethod(JuniorEGad, MUIM_Notify, MUIA_Selected, TRUE, JuniorGad, 4,
  340.        MUIM_Set, MUIA_Selected, TRUE);
  341.  
  342.   DoMethod(JuniorGad, MUIM_Notify, MUIA_Selected, TRUE, SeniorGad, 4,
  343.        MUIM_Set, MUIA_Selected, FALSE);
  344.   DoMethod(JuniorGad, MUIM_Notify, MUIA_Selected, FALSE, JuniorAGad, 4,
  345.        MUIM_Set, MUIA_Selected, FALSE);
  346.   DoMethod(JuniorGad, MUIM_Notify, MUIA_Selected, FALSE, JuniorBGad, 4,
  347.        MUIM_Set, MUIA_Selected, FALSE);
  348.   DoMethod(JuniorGad, MUIM_Notify, MUIA_Selected, FALSE, JuniorCGad, 4,
  349.        MUIM_Set, MUIA_Selected, FALSE);
  350.   DoMethod(JuniorGad, MUIM_Notify, MUIA_Selected, FALSE, JuniorDGad, 4,
  351.        MUIM_Set, MUIA_Selected, FALSE);
  352.   DoMethod(JuniorGad, MUIM_Notify, MUIA_Selected, FALSE, JuniorEGad, 4,
  353.        MUIM_Set, MUIA_Selected, FALSE);
  354.  
  355.   DoMethod(SeniorGad, MUIM_Notify, MUIA_Selected, TRUE, JuniorGad, 4,
  356.        MUIM_Set, MUIA_Selected, FALSE);
  357.   DoMethod(SeniorGad, MUIM_Notify, MUIA_Selected, TRUE, JuniorAGad, 4,
  358.        MUIM_Set, MUIA_Selected, FALSE);
  359.   DoMethod(SeniorGad, MUIM_Notify, MUIA_Selected, TRUE, JuniorBGad, 4,
  360.        MUIM_Set, MUIA_Selected, FALSE);
  361.   DoMethod(SeniorGad, MUIM_Notify, MUIA_Selected, TRUE, JuniorCGad, 4,
  362.        MUIM_Set, MUIA_Selected, FALSE);
  363.   DoMethod(SeniorGad, MUIM_Notify, MUIA_Selected, TRUE, JuniorDGad, 4,
  364.        MUIM_Set, MUIA_Selected, FALSE);
  365.   DoMethod(SeniorGad, MUIM_Notify, MUIA_Selected, TRUE, JuniorEGad, 4,
  366.        MUIM_Set, MUIA_Selected, FALSE);
  367.  
  368.   return(TRUE);
  369. }
  370. #endif    /*  AMIGA   */
  371.  
  372.  
  373.  
  374.  
  375. /*
  376.     The ProcessPlrWnd() function brings up a window and allows the user, to
  377.     enter or modify a players data. (Note, that this behaves in another
  378.     manner on the Amiga, than the other Process...() functions: The window
  379.     isn't opened by InitPlrWnd(), but by ProcessPlrWnd(). Of course this is
  380.     no must.
  381.  
  382.     Inputs:    plr - A pointer to a player structure with the defaults.
  383.         new - TRUE, if this is the first call of ProcessPlrWnd or if
  384.               plr has changed since the last call, FALSE otherwise.
  385.  
  386.     Results:    TRUE    - User selected the Ok button.
  387.         FALSE    - Error or user selected the Cancel button.
  388. */
  389. int ProcessPlrWnd(struct Player *plr, int new)
  390.  
  391. #ifdef AMIGA
  392. { ULONG open, Signal;
  393.   char *str;
  394.   ULONG flag;
  395.  
  396.   if(new)
  397.   { char elo[10];
  398.  
  399.     set(PlrWnd, MUIA_Window_ActiveObject, NameGad);
  400.     set(NameGad, MUIA_String_Contents, plr->Name);
  401.     set(StreetGad, MUIA_String_Contents, plr->Street);
  402.     set(VillageGad, MUIA_String_Contents, plr->Village);
  403.     set(ChessClubGad, MUIA_String_Contents, plr->ChessClub);
  404.     set(PhoneGad, MUIA_String_Contents, plr->PhoneNr);
  405.     set(BirthdayGad, MUIA_String_Contents, plr->BirthDay);
  406.     set(DWZGad, MUIA_String_Contents, plr->DWZ);
  407.     sprintf(elo, "%d", plr->ELO);
  408.     set(ELOGad, MUIA_String_Contents, plr->ELO);
  409.     set(SeniorGad, MUIA_Selected,
  410.     (plr->Flags & TNFLAGSF_SENIOR) ? TRUE : FALSE);
  411.     set(JuniorGad, MUIA_Selected,
  412.     (plr->Flags & TNFLAGSF_JUNIOR) ? TRUE : FALSE);
  413.     set(WomanGad, MUIA_Selected,
  414.     (plr->Flags & TNFLAGSF_WOMAN) ? TRUE : FALSE);
  415.     set(JuniorAGad, MUIA_Selected,
  416.     (plr->Flags & TNFLAGSF_JUNIORA) ? TRUE : FALSE);
  417.     set(JuniorBGad, MUIA_Selected,
  418.     (plr->Flags & TNFLAGSF_JUNIORB) ? TRUE : FALSE);
  419.     set(JuniorCGad, MUIA_Selected,
  420.     (plr->Flags & TNFLAGSF_JUNIORC) ? TRUE : FALSE);
  421.     set(JuniorDGad, MUIA_Selected,
  422.     (plr->Flags & TNFLAGSF_JUNIORD) ? TRUE : FALSE);
  423.     set(JuniorEGad, MUIA_Selected,
  424.     (plr->Flags & TNFLAGSF_JUNIORE) ? TRUE : FALSE);
  425.   }
  426.  
  427.   set(PlrWnd, MUIA_Window_Open, TRUE);
  428.   get(PlrWnd, MUIA_Window_Open, &open);
  429.   if (!open)
  430.   { MUIError((char *) GetChaosString(ERRMSG_CANNOT_OPEN_WINDOW));
  431.     return(FALSE);
  432.   }
  433.   if (new)
  434.   { set(PlrWnd, MUIA_Window_ActiveObject, NameGad);
  435.   }
  436.  
  437.   /*
  438.       Check for user actions
  439.   */
  440.   for (;;)
  441.   { switch (DoMethod(App, MUIM_Application_Input, &Signal))
  442.     { case MUIV_Application_ReturnID_Quit:
  443.     if (TestSaved())
  444.     { exit(0);
  445.     }
  446.     break;
  447.       case ID_PlrWnd_Cancel:
  448.     set(PlrWnd, MUIA_Window_Open, FALSE);
  449.     return(FALSE);
  450.       case ID_PlrWnd_Ok:
  451.     /*
  452.         Get the final state of the gadgets.
  453.     */
  454.     set(PlrWnd, MUIA_Window_Open, FALSE);
  455.     get(NameGad, MUIA_String_Contents, &str);
  456.     strcpy(plr->Name, str);
  457.     get(StreetGad, MUIA_String_Contents, &str);
  458.     strcpy(plr->Street, str);
  459.     get(VillageGad, MUIA_String_Contents, &str);
  460.     strcpy(plr->Village, str);
  461.     get(ChessClubGad, MUIA_String_Contents, &str);
  462.     strcpy(plr->ChessClub, str);
  463.     get(PhoneGad, MUIA_String_Contents, &str);
  464.     strcpy(plr->PhoneNr, str);
  465.     get(BirthdayGad, MUIA_String_Contents, &str);
  466.     strcpy(plr->BirthDay, str);
  467.     get(DWZGad, MUIA_String_Contents, &str);
  468.     strcpy(plr->DWZ, str);
  469.     get(ELOGad, MUIA_String_Contents, &str);
  470.     plr->ELO = atol(str);
  471.     plr->Flags &= ~(TNFLAGSF_SENIOR|TNFLAGSF_JUNIOR|TNFLAGSF_WOMAN|
  472.             TNFLAGSF_JUNIORA|TNFLAGSF_JUNIORB|TNFLAGSF_JUNIORC|
  473.             TNFLAGSF_JUNIORD|TNFLAGSF_JUNIORE);
  474.     get(SeniorGad, MUIA_Selected, &flag);
  475.     if (flag) plr->Flags |= TNFLAGSF_SENIOR;
  476.     get(JuniorGad, MUIA_Selected, &flag);
  477.     if (flag) plr->Flags |= TNFLAGSF_JUNIOR;
  478.     get(WomanGad, MUIA_Selected, &flag);
  479.     if (flag) plr->Flags |= TNFLAGSF_WOMAN;
  480.     get(JuniorAGad, MUIA_Selected, &flag);
  481.     if (flag) plr->Flags |= TNFLAGSF_JUNIORA;
  482.     get(JuniorBGad, MUIA_Selected, &flag);
  483.     if (flag) plr->Flags |= TNFLAGSF_JUNIORB;
  484.     get(JuniorCGad, MUIA_Selected, &flag);
  485.     if (flag) plr->Flags |= TNFLAGSF_JUNIORC;
  486.     get(JuniorDGad, MUIA_Selected, &flag);
  487.     if (flag) plr->Flags |= TNFLAGSF_JUNIORD;
  488.     get(JuniorEGad, MUIA_Selected, &flag);
  489.     if (flag) plr->Flags |= TNFLAGSF_JUNIORE;
  490.     return(TRUE);
  491.     }
  492.  
  493.     if (Signal)
  494.     { Wait(Signal);
  495.     }
  496.   }
  497.  
  498. }
  499. #endif    /*  AMIGA   */
  500.  
  501.  
  502.  
  503.  
  504. /*
  505.     The TerminatePlrSelWnd() function deletes the player select window.
  506. */
  507. #ifdef AMIGA
  508. static APTR PlrSelWnd = NULL;    /*  Player select window            */
  509. static APTR PlrSelCancelGad;    /*  Cancel gadget (player select window)    */
  510. static APTR PlrSelLV;        /*  Player listview gadget            */
  511. static APTR PlrSelReverseGad;    /*  Reverse button                */
  512. static APTR PlrSelSelGad;    /*  Select button                */
  513. void TerminatePlrSelWnd(void)
  514.  
  515. { if (PlrSelWnd)
  516.   { set(PlrSelWnd, MUIA_Window_Open, FALSE);
  517.     DoMethod(App, OM_REMMEMBER, PlrSelWnd);
  518.     MUI_DisposeObject(PlrSelWnd);
  519.     PlrSelWnd = NULL;
  520.   }
  521. }
  522. #endif
  523.  
  524.  
  525.  
  526.  
  527. #ifdef AMIGA
  528. /*
  529.     The following function is automagically called from MUI, if a player
  530.     will be displayed. (It's the displayhook of the player list.)
  531.  
  532.     Inputs: plr -   the player, that was selected.
  533.  
  534.     Result: a pointer to the players name
  535. */
  536. SAVEDS ASM static LONG DispPlayerFunc(REG(a1) struct Player *plr,
  537.                       REG(a2) char **array)
  538.  
  539. { *array = plr->Name;
  540.   return(0);
  541. }
  542. #ifdef AZTEC_C
  543. #asm
  544.             xref    _geta4
  545. _MyDispPlayerFunc:  move.l  a4,-(sp)
  546.             jsr     _geta4
  547.             move.l  a2,-(sp)
  548.             move.l  a1,-(sp)
  549.             jsr     _DispPlayerFunc
  550.             add.l   #8,sp
  551.             move.l  (sp)+,a4
  552.             rts
  553. #endasm
  554. extern LONG MyDispPlayerFunc(struct Player *, char **);
  555. #define DispPlayerFunc MyDispPlayerFunc
  556. #endif    /*  AZTEC_C */
  557. struct Hook PlrSelWnd_PlrListDispHook =
  558. { {NULL, NULL}, (void *) DispPlayerFunc, NULL, NULL
  559. };
  560.  
  561.  
  562.  
  563.  
  564. /*
  565.     The following function is called from MUI, to sort the players. It's
  566.     the comparehook of the player list.
  567.  
  568.     Inputs: plr1, plr2 - the players whose names will be compared
  569.  
  570.     Result: < 0   plr1 alphabetically before plr2
  571.         = 0   plr1 alphabetically equal plr2
  572.         > 0   plr1 alphabetically after plr2
  573. */
  574. SAVEDS ASM LONG CompPlayerFunc(REG(a1) struct Player *plr1,
  575.                    REG(a2) struct Player *plr2)
  576.  
  577. { return (Stricmp((STRPTR) plr1->Name, (STRPTR) plr2->Name));
  578. }
  579. #ifdef AZTEC_C
  580. LONG MyCompPlayerFunc(struct Player *, struct Player *);
  581. #asm
  582.             xref    _geta4
  583. _MyCompPlayerFunc:  move.l  a4,-(sp)
  584.             jsr     _geta4
  585.             move.l  a2,-(sp)
  586.             move.l  a1,-(sp)
  587.             jsr     _CompPlayerFunc
  588.             add.l   #8,sp
  589.             move.l  (sp)+,a4
  590.             rts
  591. #endasm
  592. #define CompPlayerFunc MyCompPlayerFunc
  593. #endif    /*  AZTEC_C */
  594. struct Hook PlrSelWnd_PlrListCompHook =
  595.   {{NULL, NULL}, (void *) CompPlayerFunc, NULL, NULL};
  596. #endif    /*  AMIGA   */
  597.  
  598.  
  599.  
  600.  
  601. /*
  602.     The ProcessPlrSelWnd() function brings up a list of players and allows
  603.     the user to select some.
  604.  
  605.     Inputs: wintitle    - Title of the window
  606.         buttontitle - title of the select button
  607.         buttonsc    - shortcut of the select button
  608.         flags    - Include only those players into the list, which
  609.               don't have one of flags set. (0 = Include all
  610.               players)
  611.         plrlist    - list, where the players should be read from
  612.  
  613.     Results: TRUE, if successfull, FALSE otherwise
  614.          The selected users will have TNFLAGSF_SELECTED set in their
  615.          flags field.
  616. */
  617. #ifdef AMIGA
  618. #define ID_PlrSelWnd_Cancel  300
  619. #define ID_PlrSelWnd_Player  301
  620. #define ID_PlrSelWnd_Select  302
  621. #define ID_PlrSelWnd_PlrLV   303
  622. #define ID_PlrSelWnd_Reverse 304
  623. #define ID_PlrSelWnd_Ok      305
  624.  
  625. int ProcessPlrSelWnd(char *title, char *buttontitle, char buttonsc,
  626.              int flags, struct List *plrlist)
  627.  
  628. { struct Player *plr;
  629.   ULONG open;
  630.  
  631.   PlrSelWnd = WindowObject,
  632.         MUIA_Window_Width, MUIV_Window_Width_MinMax(40),
  633.         MUIA_Window_ID, MAKE_ID('P','L','R','S'),
  634.         MUIA_Window_Title, title,
  635.         WindowContents, VGroup,
  636.             Child, PlrSelLV = ListviewObject,
  637.             MUIA_Listview_MultiSelect, TRUE,
  638.             MUIA_Listview_List, ListObject,
  639.                 MUIA_List_DisplayHook, &PlrSelWnd_PlrListDispHook,
  640.                 MUIA_List_CompareHook, &PlrSelWnd_PlrListCompHook,
  641.                 InputListFrame,
  642.             End,
  643.             End,
  644.             Child, HGroup,
  645.             Child, PlrSelSelGad = TextObject,
  646.                 ButtonFrame,
  647.                 MUIA_Text_Contents, buttontitle,
  648.                 MUIA_Text_PreParse, "\33c",
  649.                 MUIA_Text_SetMax, FALSE,
  650.                 MUIA_Text_HiChar, (int) buttonsc,
  651.                 MUIA_ControlChar, (int) buttonsc,
  652.                 MUIA_InputMode, MUIV_InputMode_RelVerify,
  653.                 MUIA_Background, MUII_ButtonBack,
  654.             End,
  655.             Child, HSpace(0),
  656.             Child, PlrSelReverseGad = TextObject,
  657.                 ButtonFrame,
  658.                 MUIA_Text_Contents, GetChaosString(Button_Reverse),
  659.                 MUIA_Text_PreParse, "\33c",
  660.                 MUIA_Text_SetMax, FALSE,
  661.                 MUIA_Text_HiChar, *GetChaosString(Button_Reverse_SC),
  662.                 MUIA_ControlChar, *GetChaosString(Button_Reverse_SC),
  663.                 MUIA_InputMode, MUIV_InputMode_RelVerify,
  664.                 MUIA_Background, MUII_ButtonBack,
  665.             End,
  666.             Child, HSpace(0),
  667.             Child, PlrSelCancelGad = TextObject,
  668.                 ButtonFrame,
  669.                 MUIA_Text_Contents, GetChaosString(MSG_CANCEL_INPUT),
  670.                 MUIA_Text_PreParse, "\33c",
  671.                 MUIA_Text_SetMax, FALSE,
  672.                 MUIA_Text_HiChar, *GetChaosString(MSG_CANCEL_SC),
  673.                 MUIA_ControlChar, *GetChaosString(MSG_CANCEL_SC),
  674.                 MUIA_InputMode, MUIV_InputMode_RelVerify,
  675.                 MUIA_Background, MUII_ButtonBack,
  676.             End,
  677.             End,
  678.         End,
  679.         End;
  680.  
  681.   if (!PlrSelWnd)
  682.   { TerminatePlrSelWnd();
  683.     return(FALSE);
  684.   }
  685.   DoMethod(App, OM_ADDMEMBER, PlrSelWnd);
  686.   DoMethod(PlrSelWnd, MUIM_Window_SetCycleChain, PlrSelLV, PlrSelSelGad,
  687.        PlrSelCancelGad, NULL);
  688.   set(PlrSelWnd, MUIA_Window_ActiveObject, PlrSelLV);
  689.  
  690.   /*
  691.       Setting up the notification events for the player select window:
  692.       CloseWindow, Ok- and Cancel Gadget and player list gadget.
  693.   */
  694.   DoMethod(PlrSelWnd, MUIM_Notify, MUIA_Window_CloseRequest, TRUE, App, 2,
  695.        MUIM_Application_ReturnID, ID_PlrSelWnd_Cancel);
  696.   DoMethod(PlrSelCancelGad, MUIM_Notify, MUIA_Pressed, FALSE, App, 2,
  697.        MUIM_Application_ReturnID, ID_PlrSelWnd_Cancel);
  698.   DoMethod(PlrSelSelGad, MUIM_Notify, MUIA_Pressed, FALSE,
  699.        App, 2, MUIM_Application_ReturnID, ID_PlrSelWnd_Ok);
  700.   DoMethod(PlrSelReverseGad, MUIM_Notify, MUIA_Pressed, FALSE,
  701.        App, 2, MUIM_Application_ReturnID, ID_PlrSelWnd_Reverse);
  702.  
  703.   for (plr = (struct Player *) plrlist->lh_Head;
  704.        plr->Tn_Node.ln_Succ != NULL;
  705.        plr = (struct Player *) plr->Tn_Node.ln_Succ)
  706.   { /*
  707.     Make sure, that no players are selected yet.
  708.     */
  709.     plr->Flags &= ~TNFLAGSF_SELECTED;
  710.  
  711.     /*
  712.     Insert those players in the list, that should be inserted.
  713.     */
  714.     if (!flags  ||  (plr->Flags & flags) == 0)
  715.     { DoMethod(PlrSelLV, MUIM_List_Insert, &plr, 1, MUIV_List_Insert_Bottom);
  716.     }
  717.   }
  718.  
  719.  
  720.   set(PlrSelWnd, MUIA_Window_Open, TRUE);
  721.   get(PlrSelWnd, MUIA_Window_Open, &open);
  722.   if (!open)
  723.   { TerminatePlrSelWnd();
  724.     return(0);
  725.   }
  726.  
  727.   /*
  728.       Check for user actions
  729.   */
  730.   for (;;)
  731.   { ULONG Signal;
  732.     LONG entries, i;
  733.  
  734.     switch (DoMethod(App, MUIM_Application_Input, &Signal))
  735.     { case MUIV_Application_ReturnID_Quit:
  736.     if (TestSaved())
  737.     { exit(0);
  738.     }
  739.     break;
  740.       case ID_PlrSelWnd_Cancel:
  741.     TerminatePlrSelWnd();
  742.     return(0);
  743.       case ID_PlrSelWnd_Ok:
  744.     for (i = -1;;)
  745.     { DoMethod(PlrSelLV, MUIM_List_NextSelected, &i);
  746.       if (i == -1)
  747.       { TerminatePlrSelWnd();
  748.         return(TRUE);
  749.       }
  750.       DoMethod(PlrSelLV, MUIM_List_GetEntry, i, &plr);
  751.       plr->Flags |= TNFLAGSF_SELECTED;
  752.     }
  753.       case ID_PlrSelWnd_Reverse:
  754.     set(PlrSelLV, MUIA_List_Quiet, TRUE);
  755.     get(PlrSelLV, MUIA_List_Entries, &entries);
  756.     for (i = 0;  i < entries;  i++)
  757.     { DoMethod(PlrSelLV, MUIM_List_Select, i, MUIV_List_Select_Toggle,
  758.            NULL);
  759.     }
  760.     set(PlrSelLV, MUIA_List_Quiet, FALSE);
  761.     break;
  762.     }
  763.  
  764.     if (Signal)
  765.     { Wait(Signal);
  766.     }
  767.   }
  768. }
  769. #endif    /*  AMIGA   */
  770.